<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class News implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $broadcastQueue = 'news-broadcast';

    public $message;

    /**
     * News constructor.
     * @param $message
     */
    public function __construct($message)
    {
        $this->message = $message;
    }

    /**
     * 事件的广播名称。
     * @return string
     */
    public function broadcastAs()
    {
        return 'news.broadcast';
    }

    /**
     * 指定广播数据
     * @return array
     */
    public function broadcastWith()
    {
        return ['id' => 51515];
    }

    /**
     * 广播触发条件
     * @return bool
     */
    public function broadcastWhen()
    {
        return true;
    }

    /**
     * @return Channel|Channel[]
     */
    public function broadcastOn()
    {
        return new Channel('news');
    }
}
